<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>

<body>
    <div id='app'>
        <form action="http://localhost:9090/fenci/upload" method="post" enctype='multipart/form-data'>
            <input type="file" name="file">
            <input type="text" name="bucket" value="cjw">
            <input type="text" name="name" value="xx.jar">
            <input type="submit" >
        </form>
        <el-input v-model="mobile">
        </el-input>
        <el-input v-model="reqUID">
        </el-input>
        <el-input v-model="content" type='textarea'>
        </el-input>
        <el-button @click="onClick">提交</el-button>
        <el-button @click="onCheck">检查</el-button>
        <el-button @click="start">一直发</el-button>
        <el-input v-model="interval" placeholder="发送延时" type='number'></el-input>
        {{timestamp}}
        <ul>
            <li>批量发送脚本</li>
            <li>浏览器跨域</li>
            <li>发送统计</li>
        </ul>
        <el-switch v-model="isRunning" active-color="#13ce66" inactive-color="#ff4949" disabled>
        </el-switch>
        <el-switch v-model="isStart" active-color="#13ce66" inactive-color="#ff4949" :disabled='!isStart'>
        </el-switch>
        <el-input-number v-model="count" :disabled="true"></el-input-number>
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.17/vue.min.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://cdn.bootcss.com/qs/6.5.2/qs.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
    <link href="https://cdn.bootcss.com/layer/2.3/skin/layer.css" rel="stylesheet">
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                inputVisible: false,
                content: 'auto sending ',
                mobile: '+8618925364423',
                reqUID: 'zzs5',
                timestamp: Date.parse(new Date()),
                url: 'http://192.168.199.175:333/getMessages.srv?hashid=591030401%40qq.com&date=0&shouldReset=1&resetHashID=%2B8618925364423&_=1544278098738',
                isRunning: false,
                isStart: false,
                count: 1,
                interval: 5000
            }
        },
        mounted: function() {},
        methods: {
            start() {
                if (this.isRunning == true) {
                    console.log('isRunning')
                    return
                } else {
                    this.isStart = true
                    this.keepRun()
                    console.log('not running')
                }
            },
            keepRun() {
                var self = this
                self.isRunning = true
                setTimeout(function() {
                    console.log('isStart: ' + self.isStart)
                    if (self.isStart) {
                        self.count += 1;
                        self.onClick()
                        self.keepRun()
                    } else {
                        self.isRunning = false
                        console.log('stopped')
                    }
                }, self.interval);
            },
            onCheck() {

                axios.get(url, {
                    params: {}
                }).then(function(response) {
                    console.log(response)
                    // alert(''.concat(response.data, '\r\n', response.status, '\r\n', response.statusText, '\r\n', response.headers, '\r\n', response.config));
                }).catch(function(error) {
                    // alert(error);
                    console.log(error)
                });
            },
            handleClose(tag, item) {},
            onClick() {
                var self = this
                // self.create()
                var content = this.content + '[' + this.count + ']'
                console.log('content')
                let formData = new FormData();
                formData.append('hashid', this.mobile);
                formData.append('reqUID', "z1al");
                formData.append('recipients', this.mobile);
                formData.append('file-name', "");
                formData.append('text', content);
                axios({
                        method: 'post',
                        url: 'http://192.168.199.175:333/sendMessage.srv',
                        data: formData,
                        //              data:{appkey: "njssdjtkj",sign:sign,sign_method:"MD5",timestamp:time,mobile:"15951971791",engine_no:"070939",plate_type:"02",plate_no:"苏EXW365"},
                        headers: {
                            'Content-Type': 'multipart/form-data'
                        }
                    })
                    .then(function(res) {
                        console.log(res)
                    })
            }
        },
        filters: {
            fmt(date) {
                return date
            }
        }
    })
    </script>
    <script>
    // vue.tableData = ${items!};
    </script>
</body>

</html>